package scjp.preparation.io;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class DataStreamExample {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String tmpFile = "C:\\Dev\\Projects\\MyProjects\\yev-playground\\bin\\scjp\\preparation\\io\\temp.data";
		try(DataOutputStream dos = new DataOutputStream(new FileOutputStream(tmpFile))){
			for(int i = 0; i< 10; i++) {
				dos.writeByte(i);
				dos.writeShort(i);
				dos.writeInt(i);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try(DataInputStream dis = new DataInputStream(new FileInputStream(tmpFile))){
			for(int i = 0; i < 10; i++) {
				System.out.printf("%d %d %d %n",
						dis.readByte(),
						dis.readShort(),
						dis.readInt()
						);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
